//
//  ZZStatusListViewModel.swift
//  SinaWeibo
//
//  Created by QUAN on 15/11/17.
//  Copyright © 2015年 QUAN. All rights reserved.
//

import UIKit
import AFNetworking
import SVProgressHUD
import SDWebImage

class ZZStatusListViewModel: NSObject {
    class func loadData(finished: (array: [ZZStatus]?) -> ()) {
        
        
        let urlString = "https://api.weibo.com/2/statuses/friends_timeline.json"
        
        guard let token = ZZUserAccountViewModel().token else {
            SVProgressHUD.showErrorWithStatus("您暂未登录!!")
            return
        }
        
        let parameters = ["access_token" : token]
        
        
        NetworkTools.sharedTools.requestJsonDict(.GET, urlString: urlString, parameters: parameters) { (result, error) -> () in
            
            if error != nil {
                finished(array: nil)
                return
            }
            
            if let array = result!["statuses"] as? [[String : AnyObject]] {
                
                var list = [ZZStatus]()
                
                for item in array {
                    
                    let s = ZZStatus(dict: item)
                    
                    list.append(s)
                }
                finished(array: list)
            }
        }
    }
}
